package meituan2024.p1;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int count = -1;

        double price1 = 0;
        double price2 = 0;
        double totalShop = 0;
        count = in.nextInt();
        if (count <= 0) {
            System.out.println("error");
            return;
        }
        //商品价格
        while (count-- > 0) {
            double originalPrice = in.nextFloat();
            double disCount = in.nextFloat();
            if (originalPrice <= 0 || disCount <= 0 || originalPrice - disCount < 0) {
                System.out.println("error");
                return;
            }
            price1 += disCount;
            totalShop += originalPrice;
        }

        double total = in.nextFloat();
        double discount = in.nextFloat();

        if (total <= 0 || discount <= 0 || discount - total > 0) {
            System.out.println("error");
            return;
        }

        price2 = (totalShop - total) >= 0 ? (totalShop - discount) : totalShop;

        double result = Math.min(price1, price2);

        DecimalFormat decimalFormat = new DecimalFormat(".00");
        System.out.println(decimalFormat.format(result));
    }

}